home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / fsortm.zip / FSORTM.DOC < prev   
Text File  |  1993-01-04  |  3KB  |  63 lines

  1.             Fast SORT Multikey
  2.             ------------------
  3.  
  4. FSORTM.BIN is an external assembly language program for use with Turbo Pascal that gives very high speed sort capability on multiple keys. It for sure runs with Turbo Pascal version 3.01A (the latest version Borland has released) and should run with the earlier versions, provided the bug on the the size of external assembly language programs is worked around.
  5.  
  6. Usage:
  7.  
  8. const
  9.    MAXKEYS  = (however many keys you will use) ;
  10.  
  11. type
  12.    KeyType  = array[1..MAXKEYS] of integer ;
  13.  
  14. procedure Sort(RecLen  : integer ;    {Size of each array record     }
  15.            NumKeys : integer ;    {Number of sort keys being used}
  16.        var KeyPos  : KeyType ;       {Array of sort key positions   }
  17.        var KeyLen  : KeyType ;    {Array of sort key lengths     }
  18.            RecCnt  : integer ;    {Number of records to sort     }
  19.                Base    : integer ) ;    {Segment address of array      }
  20. external 'FSORTM.BIN' ;
  21.  
  22. IMPORTANT NOTE:
  23. This version of FSORTM is designed for use with arrays created on Turbo's
  24. Heap using the "New" or "GetMem" procedures. It is NOT designed to be used
  25. with arrays that are defined in Turbo Pascal's Data Segment, or anywhere
  26. where the array to be sorted cannot for sure be made to start on a paragraph
  27. (16 byte) boundary in the 8088/8086 address space. This is a compromise that
  28. permits very high speed sorting by cutting down on the address computation.
  29.  
  30. For the same reason, the size of RecLen MUST be a multiple of 16 bytes
  31. otherwise unpredictable happenings will occur during the sort. The sort
  32. routine depends for its operation on the records being adressable with the
  33. just 8088 segment registers. As a result the base address of the array
  34. must have an offset divisible by 16, i.e. the address of the array must be
  35. on a paragraph (16 byte) boundary in the 8088 adress space. This is guaranteed
  36. by the "New" procedure in Turbo Pascal if the sort array is the FIRST variable
  37. allocated memory space on the heap.
  38.  
  39. Although not covered in the Turbo Pascal Reference Manual the minimum
  40. allocation unit that either "New" or "GetMem" uses is 8 bytes. Therefore, byte allocations on Turbo's heap go like this:
  41.  
  42.     Variable Size in bytes        Allocation in bytes
  43.     ----------------------          -------------------
  44.  
  45.          1 -  8                 8
  46.          9 - 16                16
  47.         17 - 24                24
  48.         25 - 32                32
  49.           etc.                etc.
  50.  
  51. So, the current offset of the predefined variable "HeapPtr" can be checked
  52. to see if it zero, and if it isn't, allocate a pointer to type byte before
  53. allocating for the array to be sorted. This would only be needed if there had
  54. been a previous use of "GetMem" and/or "New" in the program. It can easily
  55. done like this:
  56.  
  57.     var
  58.        BytePtr  : ^byte ;
  59.  
  60.     if Ofs(HeapPtr^) <> 0 then
  61.        New(BytePtr) ;
  62.  
  63.